<?php
class FocusAreasController extends AppController {

	var $name = 'FocusAreas';
      
      function beforeFilter() {
        parent::beforeFilter();
	$this->Auth->autoRedirect = false;
	$this->Auth->allowedActions = array('add');
    }
	function index() {
		$this->FocusArea->recursive = 0;
		$this->set('focusAreas', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid focus area', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('focusArea', $this->FocusArea->read(null, $id));
	}

	function add() {
	//$headers = getallheaders();
      //  if (isset($headers['x-requested-with']))
       // {
       //    
       // }
           // $this->layout = 'ajax';
            if (!empty($this->data)) {
			$this->FocusArea->create();
			if ($this->FocusArea->save($this->data)) {
				$this->Session->setFlash(__('The focus area has been saved', true));
				//$this->redirect(array('action' => 'index'));
			} else {
                                $this->Session->setFlash(__('The focus area could not be saved. Please, try again.', true));
			}
                       // $this->autoRender=false;
		}
             //$this->RequestHandle // $this->render('add','ajax');r->setAjax($this);     
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid focus area', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->FocusArea->save($this->data)) {
				$this->Session->setFlash(__('The focus area has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The focus area could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->FocusArea->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for focus area', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->FocusArea->delete($id)) {
			$this->Session->setFlash(__('Focus area deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Focus area was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function backstage_index() {
		$this->FocusArea->recursive = 0;
		$this->set('focusAreas', $this->paginate());
	}

	function backstage_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid focus area', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('focusArea', $this->FocusArea->read(null, $id));
	}

	function backstage_add() {
		if (!empty($this->data)) {
			$this->FocusArea->create();
			if ($this->FocusArea->save($this->data)) {
				$this->Session->setFlash(__('The focus area has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The focus area could not be saved. Please, try again.', true));
			}
		}
	}

	function backstage_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid focus area', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->FocusArea->save($this->data)) {
				$this->Session->setFlash(__('The focus area has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The focus area could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->FocusArea->read(null, $id);
		}
	}

	function backstage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for focus area', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->FocusArea->delete($id)) {
			$this->Session->setFlash(__('Focus area deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Focus area was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
